#include <iostream>
#include <iomanip>
int main()
{	
	int n = 0, active = 0, numersFound = 0;
	std::cin >> n;
	for (int i = 1; i <= n; i++)
	{
		if (i % 3 == 0 || i % 5 == 0 || i % 7 == 0)
		{
			std::cout << std::setw(8) << i;
			numersFound++;
			active = 1;
		}
		if (numersFound % 8 == 0 && active)
		{
			std::cout << std::endl;
			active = 0;
		}
	}
}